/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.common.source.network.interceptor;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author Young Ken
 */

public class CacheInterceptor implements Interceptor {
    private int mMaxAge = 60 * 60 * 24 * 7;

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response response = chain.proceed(request);

        return response.newBuilder()
                .removeHeader("Pragma")
                .removeHeader("Cache-Control")
                .header("Cache-Control", "no-cache, max-age=" + mMaxAge)
                .build();
    }

    /**
     * create cacheFactory
     *
     * @return CacheInterceptor
     */
    public static CacheInterceptor create() {
        return new CacheInterceptor();
    }
}
